package com.cmse.service.impl;

import java.util.List;

import com.cmse.persistence.dao.IBaseDao;
import com.cmse.persistence.enmu.FetchOrderType;
import com.cmse.service.IBaseService;

/**
 * @author wulibin, exceptsky@gmail.com, 2012-3-15 下午1:38:45
 * 
 */
public class BaseService<T> implements IBaseService<T>{
	protected IBaseDao<T> dao;
	protected int pageLength = 10;
	
	@Override
	public void add(T entity) {
		dao.add(entity);
	}

	@Override
	public void delete(long id) {
		dao.delete(id);
	}

	@Override
	public void deleteBatch(long[] ids) {
		dao.deleteBatch(ids);
	}

	@Override
	public T get(long id) {
		return dao.get(id);
	}

	@Override
	public void update(T entity) {
		dao.update(entity);
	}

	@Override
	public List<T> getAll(FetchOrderType orderType) {
		return dao.getAll(orderType);
	}

	
	@Override
	public List<T> getPage(int page, FetchOrderType orderType) {
		return dao.getPage(page * pageLength, pageLength, orderType);
	}

	@Override
	public long getTotalCount() {
		return dao.getTotalCount();
	}

	@Override
	public List<T> getByCondition(T expEntity, int page, FetchOrderType orderType) {
		return dao.getByCondition(expEntity, page*pageLength, pageLength, orderType);
	}
	
	@Override
	public long getCountByCondition(T expEntity) {
		return dao.getCountByCondition(expEntity);
	}
	
	public void setDao(IBaseDao<T> dao) {
		this.dao = dao;
	}
	
	public void setPageLength(int length){
		this.pageLength = length;
	}
}
